$(function () {
    window.$containerObj = {
        main: $('#container'),  // container元素
        data: {}, // hospital、type、assets、year数据
        init: function () {
            this.totalObj.init(); // 初始化 概览框 对象
            this.chartObj.init(); // 初始化 echart 对象
            this.modalObj.init(); // 初始化 详情模态框 对象
        },
        /* 查询hospital、type、assets、year数据 */
        queryData: function (tag, params, fn) { // tag: hospital、type、assets、year, params: 筛选条件, fn: 回调函数
            var $this = this;
            var url = basePath + 'charts/area/allocation/' + tag;
            publicAjax(url, 'post', $.extend({}, $headerObj.searchObj.params, params || {}, params), function (data) {
                $this.data[tag] = data.data || {list: []};  // 设置$containerObj对象data数据
                $this.data[tag].list.calTotal();  // 计算总数，按照curPrice排序
                // 设置模态框数据
                $this.modalObj.data[tag] = $.extend(true, {}, $this.data[tag]);
                if (fn) {fn();} else {
                    if (tag === 'type') {  // 设置echart图表数据
                        $this.chartObj.convertData(); // chartObj转换echart所用数据
                        $this.chartObj.setChart();  // chartObj设置echart图表
                    }
                    // 获取数据长度，用于计算TOP5显示条数
                    var length = tag === 'type'
                        ? $this.data[tag].list[-1].list ? $this.data[tag].list[-1].list.length : 0
                        : $this.data[tag].list.length;
                    $this.top5Obj.convertData(tag, 0, length > 5 ? 5 : length); // top5Obj转化数据，及设置TOP5列表
                    /* 如果模态框显示则刷新模态框数据 */
                    if ($this.modalObj.main.is(':visible') || $this.modalObj.yearMain.is(':visible')) {
                        $this.modalObj.setModal($this.modalObj.main.data().tag, 'curPrice', 'desc');
                    }
                }
            }, true);
        },
        /* 点击TOP5列表及详情模态框跳转关系 */
        query: function (tag, id) {
            var $this = this;
            if (tag === 'hospital') { // 如果是医院就跳转到医院报表
                window.open(basePath + 'charts/hospital/type-index/page?hospitalId=' + id);
            } else if (tag === 'type') {  // 如果是设备类型，设置设备类型参数，并跳转到设备型号页面
                location.href = basePath + 'charts/area/allocation/model-page?typeId=' + id;
            } else if (tag === 'assets') {  // 如果是具体设备就跳转到设备详情页面
                window.open(basePath + 'charts/overview/assets/page?deviceId=' + id);
            } else if (tag === 'year') {  // 如果是历年数据，筛选年份数据
                this.queryData('type', {year: id}, function () {
                    $this.modalObj.setModal('type', 'curPrice', 'desc', ',year:' + id);
                });
            }
        }
    };
    /* 概览框对象 */
    $containerObj.totalObj = {
        main: $containerObj.main.find('.main-total'), // 概览框元素
        data: {}, // 概览框数据
        init: function () {
            this.queryData(); // 查询概览框数据
        },
        /* 查询概览框数据 flag：点击气泡时，传true，只查询除气泡图以外的数据 */
        queryData: function (flag, index, length) {
            var $this = this;
            if (flag) {
                /* 设置top5数据 */
                if (length > 5) {
                    if (index > length - 3) {
                        $containerObj.top5Obj.convertData('type', length - 5, length, index);
                    }
                    if (index < 2) {
                        $containerObj.top5Obj.convertData('type', 0, length > 5 ? 5 : length, index);
                    } else {
                        $containerObj.top5Obj.convertData('type', index - 2, index + 3, index);
                    }
                } else {
                    $containerObj.top5Obj.convertData('type', 0, length, index);
                }
                $containerObj.queryData('hospital');
                $containerObj.queryData('assets');
            } else {
                publicAjax(basePath + 'charts/area/allocation/overview-type', 'post', $headerObj.searchObj.params, function (data) {
                    $this.data = data.data;
                    $this.setData();  // 设置数据

                    $containerObj.queryData('hospital');
                    $containerObj.queryData('type');
                    $containerObj.queryData('assets');
                    // 触发 历年数据、全部数据 下拉框，使页面显示全部数据
                    $containerObj.chartObj.changeSelect.val(0).trigger('change');
                }, true);
            }
        },
        /* 设置概览框数据 */
        setData: function () {
            var $this = this;
            // 设置标题设备金额范围
            var totalTitle = this.main.find('.total-title'),
                radio = $headerObj.searchObj.main.find('input[name="assets-price"]'),
                range = radio.eq(1).data();
            totalTitle.eq(1).html('≥' + range.max + $.i18n.prop('share.unit.wanyuan'));
            totalTitle.eq(2).html(range.min + '-' + range.max + $.i18n.prop('share.unit.wanyuan'));
            totalTitle.eq(3).html('<' + range.min + $.i18n.prop('share.unit.wanyuan'));
            totalTitle.off().on('click', function () {
                loading();
                var index = $(this).index('.total-title');
                radio.eq(3 - index).trigger('ifChecked');
                $headerObj.searchObj.params.priceStart = $headerObj.searchObj.main.find('#priceStart').val() ? $headerObj.searchObj.main.find('#priceStart').val() * PRICE_CONVERT : $headerObj.searchObj.main.find('#priceStart').val();
                $headerObj.searchObj.params.priceEnd = $headerObj.searchObj.main.find('#priceEnd').val() ? $headerObj.searchObj.main.find('#priceEnd').val() * PRICE_CONVERT : $headerObj.searchObj.main.find('#priceEnd').val();
                totalTitle.removeClass('active').eq(index).addClass('active');
                $containerObj.queryData('hospital');
                $containerObj.queryData('type');
                $containerObj.queryData('assets');
            });

            var allAssets = this.data.allAssets;
            this.main.find('#assets-price-1').text(fix2(allAssets.curPrice / PRICE_CONVERT));  // 设备金额
            this.main.find('#assets-price-yoy-1').text(Math.abs(fix2(allAssets.devicePriceYoy)) + '%')  // 同比
                .next().find('img').attr('src', allAssets.devicePriceYoy >= 0
                ? basePath + 'plugins/charts/images/arrow_up.png'
                : basePath + 'plugins/charts/images/arrow_down.png'
            );
            this.main.find('#assets-count-1').text(fix0(allAssets.curCounts));  // 设备数量
            this.main.find('#assets-count-yoy-1').text(Math.abs(fix2(allAssets.deviceCountsYoy)) + '%')  // 同比
                .next().find('img').attr('src', allAssets.deviceCountsYoy >= 0
                ? basePath + 'plugins/charts/images/arrow_up.png'
                : basePath + 'plugins/charts/images/arrow_down.png'
            );
            this.main.find('#hospital-count-1').text(fix0(allAssets.hospitalCounts));  // 医院数量
            this.main.find('#type-count-1').text(fix0(allAssets.typeCounts));  // 设备类型数量

            var amountList = this.data.amountList;
            for (var i = 0; i < amountList.length; i++) {
                this.main.find('#assets-price-' + (i + 2)).text(fix2(amountList[i].curPrice / PRICE_CONVERT));  // 设备金额
                this.main.find('#assets-price-yoy-' + (i + 2)).text(Math.abs(fix2(amountList[i].devicePriceYoy)) + '%')  // 同比
                    .next().find('img').attr('src', amountList[i].devicePriceYoy >= 0
                    ? basePath + 'plugins/charts/images/arrow_up.png'
                    : basePath + 'plugins/charts/images/arrow_down.png'
                );
                this.main.find('#assets-count-' + (i + 2)).text(fix0(amountList[i].curCounts));  // 设备数量
                this.main.find('#assets-count-yoy-' + (i + 2)).text(Math.abs(fix2(amountList[i].deviceCountsYoy)) + '%')  // 同比
                    .next().find('img').attr('src', amountList[i].deviceCountsYoy >= 0
                    ? basePath + 'plugins/charts/images/arrow_up.png'
                    : basePath + 'plugins/charts/images/arrow_down.png'
                );
                this.main.find('#hospital-count-' + (i + 2)).text(fix0(amountList[i].hospitalCounts));  // 医院数量
                this.main.find('#type-count-' + (i + 2)).text(fix0(amountList[i].typeCounts));  // 设备类型数量
            }
        }
    };
    /* echart对象 */
    $containerObj.chartObj = {
        main: $containerObj.main.find('.main-chart'), // echarts图表模块主元素
        changeSelect: $('#chart-change'), // 历年数据/全部数据 下拉框
        data: { // echarts图表数据
            seriesData: [],
            sizeMin: 0,
            sizeMax: 0,
            sizeRange: 0
        },
        yearData: { // 历年数据
            seriesData: [],
            xAxis: []
        },
        init: function () {
            this.initChart(); // 初始化echats图表
            this.bindEvent(); // 绑定事件
        },
        /* 初始化echarts图表 */
        initChart: function () {
            this.chart = echarts.init(this.main.find('#chart')[0]);
            this.chart.on('click', this.click.bind(this));  // echarts绑定click事件
        },
        /* echarts图表click事件，点击气泡，top5高亮，筛选其他数据 */
        click: function (params) {
            if ((params.componentType !== 'markLine') && (this.changeSelect.val() !== '1')) { // 点击的不是平均线及历年数据不显示
                loading();
                setTimeout(function () {
                    var index = params.dataIndex, // 点击气泡图的index
                        id = params.data[6],
                        length = $containerObj.data.type.list[-1].list.length; // 医院列表的长度
                    var selectType = $('.select_type'); // type筛选框
                    /* 点击的气泡已经筛选了，就取消高亮，没筛选就加上高亮 */
                    if ((selectType.val() || []).join(',') === [id].join(',')) {
                        selectType.val('').trigger('change');
                        $headerObj.searchObj.params.typeId = null;
                        index = -1;
                        $containerObj.totalObj.queryData(true, index, length);
                    } else {
                        selectType.val(id).trigger('change');
                        $headerObj.searchObj.params.typeId = JSON.stringify([id]);
                        index = $containerObj.data.type.list[-1].list.getIndexByKey('id', id);
                        $containerObj.totalObj.queryData(true, index, length);
                    }
                }, 10);
            }
        },
        /* 转换echarts数据 */
        convertData: function () {
            var data = $containerObj.data.type;
            this.data.seriesData = [];
            var ageLimitMeasureArr = [];
            data.list[-1].list = data.list[-1].list || [];
            for (var i = 0; i < data.list[-1].list.length; i++) {
                this.data.seriesData.push([
                    fixLine(data.list[-1].list[i].curPrice / PRICE_CONVERT),
                    fixLine(data.list[-1].list[i].curCounts),
                    fixLine(data.list[-1].list[i].curAgeLimitMeasure),
                    fixStr(data.list[-1].list[i].name),
                    fixLine(data.list[-1].list[i].devicePriceYoy),
                    fixLine(data.list[-1].list[i].deviceCountsYoy),
                    data.list[-1].list[i].id
                ]);
                ageLimitMeasureArr.push(data.list[-1].list[i].curAgeLimitMeasure);
            }
            this.data.sizeMin = ageLimitMeasureArr.min();
            this.data.sizeMax = ageLimitMeasureArr.max();
            this.data.sizeRange = this.data.sizeMax - this.data.sizeMin;
            this.data.avgCounts = fix0(data.avgCounts);
            this.data.avgPrice = fix2(data.avgPrice / PRICE_CONVERT);
        },
        /* 设置echarts图表 */
        setChart: function () {
            this.optionChart.series[0].data = this.data.seriesData;
            this.optionChart.series[0].markLine.data[0].xAxis = this.data.avgPrice;
            this.optionChart.series[0].markLine.data[1].yAxis = this.data.avgCounts;

            this.chart.clear();
            this.chart.setOption(this.optionChart);
        },
        /* 查询历年数据 */
        queryYearData: function () {
            var $this = this;
            publicAjax(basePath + 'charts/area/allocation/year-trend', 'post', $headerObj.searchObj.params, function (data) {
                $containerObj.data.year = data.data;
                $this.convertYearData();
                $this.setYearChart();
                $containerObj.top5Obj.convertData('year', 0, data.data.list.length);
                // 设置模态框数据
                $containerObj.modalObj.data.year = $.extend(true, {}, $containerObj.data.year);
                loading(true);
            }, true);
        },
        /* 转换历年数据 */
        convertYearData: function () {
            var data = $containerObj.data.year;
            this.yearData.xAxis = [];
            this.yearData.seriesData = [[], []];
            for (var i = 0; i < data.list.length; i++) {
                this.yearData.xAxis.push(data.list[i].name);
                this.yearData.seriesData[0].push(data.list[i].curPrice / PRICE_CONVERT);
                this.yearData.seriesData[1].push(data.list[i].curCounts);
            }
        },
        /* 设置历年数据echarts图表 */
        setYearChart: function () {
            this.optionYear.xAxis.data = this.yearData.xAxis;
            this.optionYear.series[0].data = this.yearData.seriesData[0];
            this.optionYear.series[1].data = this.yearData.seriesData[1];

            this.chart.clear();
            this.chart.setOption(this.optionYear);
        },
        /* 绑定事件 */
        bindEvent: function () {
            var $this = this;
            var yearBtn = this.main.find('.year-btn'),
                chartTitle = this.main.find('.chart-title');
            yearBtn.on('click', function () {
                var value = 1 - parseInt($this.changeSelect.val());
                $this.changeSelect.val(value).trigger('change');
            });
            /* 历年数据/全部显示 下拉框change事件 */
            this.changeSelect.on('change', function () {
                var value = parseInt($(this).val());
                if (value) {
                    loading();
                    yearBtn.addClass('active').find('span').html($.i18n.prop('charts.button.qbxs'));
                    chartTitle.html($.i18n.prop('charts.button.lnsj')).data().tag = 'year';
                    $this.main.find('.quadrantContainner').hide();
                    $containerObj.top5Obj.changeShow(value);
                    $this.queryYearData();
                } else {
                    yearBtn.removeClass('active').find('span').html($.i18n.prop('charts.button.lnsj'));
                    chartTitle.html($.i18n.prop('charts.title.sblxfb')).data().tag = 'type';
                    $this.main.find('.quadrantContainner').show();
                    $containerObj.top5Obj.changeShow(value);
                    $this.chart.clear();
                    $this.chart.setOption($this.optionChart);
                }
            });

            /* 处理象限点击 */
            var currentOptionTemp,
                optionAgelimit = this.optionChart;
            this.main.find('.quadrant').on('click', function () {
                var index = $(this).index();
                var arr = optionAgelimit.series[0].data;
                var markLimeArr = optionAgelimit.series[0].markLine.data;
                var arrTemp = [];
                currentOptionTemp = optionAgelimit;
                if ($(this).hasClass('active')) {
                    $(this).removeClass('active');
                    arrTemp = arr;
                    currentOptionTemp.series[0].markLine.data = markLimeArr;
                } else if (index === 1) {
                    $(this).addClass('active').siblings().removeClass('active');
                    for (var i = 0; i < arr.length; i++) {
                        if ((parseFloat(arr[i][0]) >= parseFloat(markLimeArr[0].xAxis)) && (parseFloat(arr[i][1]) >= parseFloat(markLimeArr[1].yAxis))) {
                            arrTemp.push(arr[i]);
                        } else {
                            arrTemp.push([0, 0, 0, i])
                        }
                    }
                    currentOptionTemp.series[0].markLine.data = [];
                } else if (index === 2) {
                    $(this).addClass('active').siblings().removeClass('active');
                    for (var i = 0; i < arr.length; i++) {
                        if ((parseFloat(arr[i][0]) < parseFloat(markLimeArr[0].xAxis)) && (parseFloat(arr[i][1]) >= parseFloat(markLimeArr[1].yAxis))) {
                            arrTemp.push(arr[i]);
                        } else {
                            arrTemp.push([0, 0, 0, i])
                        }
                    }
                    currentOptionTemp.series[0].markLine.data = [];
                } else if (index === 3) {
                    $(this).addClass('active').siblings().removeClass('active');
                    for (var i = 0; i < arr.length; i++) {
                        if ((parseFloat(arr[i][0]) < parseFloat(markLimeArr[0].xAxis)) && (parseFloat(arr[i][1]) < parseFloat(markLimeArr[1].yAxis))) {
                            arrTemp.push(arr[i]);
                        } else {
                            arrTemp.push([0, 0, 0, i])
                        }
                    }
                    currentOptionTemp.series[0].markLine.data = [];
                } else if (index === 4) {
                    $(this).addClass('active').siblings().removeClass('active');
                    for (var i = 0; i < arr.length; i++) {
                        if ((parseFloat(arr[i][0]) >= parseFloat(markLimeArr[0].xAxis)) && (parseFloat(arr[i][1]) < parseFloat(markLimeArr[1].yAxis))) {
                            arrTemp.push(arr[i]);
                        } else {
                            arrTemp.push([0, 0, 0, i])
                        }
                    }
                    currentOptionTemp.series[0].markLine.data = [];
                }
                currentOptionTemp.series[0].data = arrTemp;
                $this.chart.clear();
                $this.chart.setOption(currentOptionTemp);
                optionAgelimit.series[0].data = arr;
                optionAgelimit.series[0].markLine.data = markLimeArr;
            });
        },
        optionChart: {
            color: ['#31860f'],
            backgroundColor: '#373945',
            tooltip: {
                trigger: 'item',
                textStyle: {
                    fontSize: 0.28 * rem
                },
                formatter: function (a) {
                    if (a.componentType === 'markLine') {
                        return a.name + ':' + a.value;
                    } else {
                        return a.data[3] + '<br/>'
                            + $.i18n.prop('share.overview.sbje') + '：' + fix2(a.data[0]) + $.i18n.prop('share.unit.wanyuan') + '<br/>'
                            + $.i18n.prop('share.overview.sbsl') + '：' + fix0(a.data[1]) + $.i18n.prop('share.unit.tai') + '<br/>'
                            + $.i18n.prop('charts.index.sbjetb') + '：' + fix2(a.data[4]) + '%<br/>'
                            + $.i18n.prop('charts.index.sbsltb') + '：' + fix2(a.data[5]) + '%<br/>'
                            + $.i18n.prop('share.assets.nxzs') + '：' + fix2(a.data[2]);
                    }
                }
            },
            dataZoom: [{
                type: 'inside',
                xAxisIndex: [0],
                start: 0,
                end: 100
            },
                {
                    type: 'inside',
                    yAxisIndex: [0],
                    start: 0,
                    end: 100
                }
            ],
            grid: {
                top: 1.6 * rem,
                left: rem * 0.4,
                right: 2.4 * rem,
                bottom: 0,
                containLabel: true
            },
            xAxis: {
                name: $.i18n.prop('charts.axis.sbje-wy'),
                type: 'value',
                nameTextStyle: {
                    color: '#fff',
                    fontSize: 0.28 * rem
                },
                axisLabel: {
                    show: true,
                    fontSize: parseInt(0.28 * rem),
                    textStyle: {
                        color: '#fff'
                    }
                },
                splitLine: {
                    show: false,
                    lineStyle: {
                        color: '#f00',
                        type: 'dashed'
                    }
                },
                axisLine: {
                    lineStyle: {
                        color: '#fff'
                    }
                },
                axisTick: {
                    lineStyle: {
                        color: '#fff'
                    }
                }
            },
            yAxis: [{
                name: $.i18n.prop('charts.axis.sbsl-t'),
                type: 'value',
                nameTextStyle: {
                    color: '#fff',
                    fontSize: 0.28 * rem
                },
                axisLabel: {
                    show: true,
                    fontSize: 0.28 * rem,
                    textStyle: {
                        color: '#fff'
                    }
                },
                splitLine: {
                    show: false,
                    lineStyle: {
                        color: '#f00',
                        type: 'dashed'
                    }
                },
                axisLine: {
                    lineStyle: {
                        color: '#fff'
                    }
                },
                axisTick: {
                    lineStyle: {
                        color: '#fff'
                    }
                }
            }],
            series: [{
                type: 'scatter',
                data: [],
                symbolSize: function (data) {
                    if (data[2] === 0) return 0;
                    if ($containerObj.chartObj.data.sizeRange == 0) return 35;
                    return data[2] === 0 ? 0 : (30 * (data[2] - $containerObj.chartObj.data.sizeMin) / $containerObj.chartObj.data.sizeRange + 20);
                },
                markLine: {
                    lineStyle: {
                        normal: {
                            color: MARKLINE_COLOR,
                            type: 'dashed',
                            opacity: 0.4
                        }
                    },
                    data: [
                        {type: 'average', name: $.i18n.prop('charts.avg.sbjepjz(wy)'), valueIndex: 0, xAxis: null},
                        {type: 'average', name: $.i18n.prop('charts.avg.sbslpjz(t)'), valueIndex: 1, yAxis: null}
                    ]
                }
            }]
        },
        optionYear: {
            color: ['#2089ff', '#6c63ff', '#12a0df', '#fb8a22', '#fef534'],
            backgroundColor: '#373945',
            tooltip: {
                trigger: 'axis',
                axisPointer: { // 坐标轴指示器，坐标轴触发有效
                    type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
                },
                textStyle: {
                    fontSize: 0.28 * rem
                },
                formatter: function (params) {
                    return params[0].name + '：<br>' +
                        $.i18n.prop('share.overview.sbje') + '：' + fix2(params[0].value) + $.i18n.prop('share.unit.wanyuan') + '<br>' +
                        $.i18n.prop('share.overview.sbsl') + '：' + fix0(params[1].value) + $.i18n.prop('share.unit.tai');
                }
            },
            legend: {
                x: "right",
                top: 0.4 * rem,
                textStyle: {
                    color: '#AAA',
                    fontSize: 0.28 * rem
                },
                data: [$.i18n.prop('share.overview.sbje'), $.i18n.prop('share.overview.sbsl')]
            },
            grid: {
                top: 1.6 * rem,
                left: rem * 0.4,
                right: rem,
                bottom: 0,
                containLabel: true
            },
            xAxis: {
                type: 'category',
                data: [],
                nameTextStyle: {
                    color: '#fff',
                    fontSize: 0.28 * rem
                },
                axisLabel: {
                    show: true,
                    fontSize: parseInt(0.28 * rem),
                    textStyle: {
                        color: '#fff'
                    }
                },
                splitLine: {
                    show: false,
                    lineStyle: {
                        color: '#f00',
                        type: 'dashed'
                    }
                },
                axisLine: {
                    lineStyle: {
                        color: '#fff'
                    }
                },
                axisTick: {
                    lineStyle: {
                        color: '#fff'
                    }
                }
            },
            yAxis: [{
                name: $.i18n.prop('share.unit.wanyuan'),
                type: 'value',
                nameTextStyle: {
                    color: '#fff',
                    fontSize: 0.28 * rem
                },
                axisLabel: {
                    show: true,
                    fontSize: parseInt(0.28 * rem),
                    textStyle: {
                        color: '#fff'
                    }
                },
                splitLine: {
                    show: false,
                    lineStyle: {
                        color: '#fff',
                        type: 'dashed'
                    }
                },
                axisLine: {
                    lineStyle: {
                        color: '#fff'
                    }
                },
                axisTick: {
                    lineStyle: {
                        color: '#fff'
                    }
                }
            }, {
                name: $.i18n.prop('share.unit.tai'),
                type: 'value',
                nameTextStyle: {
                    color: '#fff',
                    fontSize: 0.28 * rem
                },
                axisLabel: {
                    show: true,
                    fontSize: parseInt(0.28 * rem),
                    textStyle: {
                        color: '#fff'
                    }
                },
                splitLine: {
                    show: false,
                    lineStyle: {
                        color: '#fff',
                        type: 'dashed'
                    }
                },
                axisLine: {
                    lineStyle: {
                        color: '#fff'
                    }
                },
                axisTick: {
                    lineStyle: {
                        color: '#fff'
                    }
                }
            }],
            series: [{
                name: $.i18n.prop('share.overview.sbje'),
                type: 'bar',
                barGap: '0%',
                barMaxWidth: 0.8 * rem,
                data: []
            }, {
                name: $.i18n.prop('share.overview.sbsl'),
                type: 'bar',
                yAxisIndex: 1,
                barMaxWidth: 0.8 * rem,
                data: []
            }]
        }
    };
    /* Top5对象 */
    $containerObj.top5Obj = {
        main: $containerObj.main.find('.main-top5'), // top5主对象
        data: {}, // top5数据存储 hospital、type、assets、year
        status: {
            array: {},
            getStatus: function () {
                var arr = $headerObj.page[$headerObj.page.current].query;
                for (var i = 0; i < arr.length; i++) {
                    if (!this.array[arr[i]]) return false;
                }
                return true;
            },
            resetStatus: function () {
                for (var key in this.array) {
                    this.array[key] = false;
                }
            }
        },
        /* top5对象初始化方法 */
        init: function () {

        },
        /* 切换显示 历年数据（传值） or 全部显示 */
        changeShow: function (value) {
            if (value) {
                this.main.find('.top5').hide();
                this.main.find('.top5-year, .top5-assets').show();
            } else {
                this.main.find('.top5-year').hide().siblings('.top5').show();
            }
        },
        /* 转化top5数据 */
        convertData: function (tag, start, end, index) {
            this.status.array[tag] = true;
            var data = $containerObj.data;
            var priceCount = $containerObj.totalObj.data.allAssets.curPrice;
            this.data[tag] = [];
            if (tag === 'type') {
                var data2 = data[tag].list[-1].list ? data[tag].list[-1] : {list: []};
                (data2.list || []).sortByKey('curPrice');
                for (var i = start; i < end; i++) {
                    this.data[tag].push([
                        data2.list[i].name,
                        data2.list[i].id,
                        data2.list[i].curPrice / PRICE_CONVERT,
                        data2.list[i].curPrice * 100 / priceCount,
                        i === index
                    ]);
                }
            } else {
                for (var i = start; i < end; i++) {
                    this.data[tag].push([
                        data[tag].list[i].name,
                        data[tag].list[i].id,
                        data[tag].list[i][tag === 'assets' ? 'price' : 'curPrice'] / PRICE_CONVERT,
                        data[tag].list[i][tag === 'assets' ? 'price' : 'curPrice'] * 100 / priceCount,
                        i === index
                    ]);
                }
            }
            this.setData(tag, start + 1);
            if (this.status.getStatus()) {
                loading(true);
                this.status.resetStatus();
            }
        },
        /* 设置top5数据 */
        setData: function (tag, start) {
            var str = '',
                active = '';
            for (var i = 0; i < this.data[tag].length; i++) {
                active = this.data[tag][i][4] ? ' class="active"' : '';
                str += (
                    '<li><a' + active + '>' +
                    '<span onclick="$containerObj.query(\'' + tag + '\',\'' + this.data[tag][i][1] + '\')" ' +
                    'title="' + (start + i) + ' ' + fixStr(this.data[tag][i][0]) + '" class="top5-key underline">' + fixStr(this.data[tag][i][0]) + '</span>' +
                    (tag === 'year'
                        ? '<span class="top5-value1"></span>'
                        : '<span data-value="' + fix2(this.data[tag][i][3]) + '" class="top5-value1 jqmeter"></span>') +
                    '<span class="top5-value2">' + fix2(this.data[tag][i][2]) + '</span>' +
                    '</a></li>'
                );
            }
            this.main.find('.top5-' + tag + ' ul').html(str);
            this.initJQMeter(tag);
        },
        /* 初始化进度条 */
        initJQMeter: function (tag) {
            this.main.find('.top5-' + tag + ' .jqmeter').each(function () {
                $(this).jQMeter({
                    goal: '$1,00',
                    raised: '$' + parseInt($(this).data().value),
                    width: '90%',
                    height: '0.24rem'
                });
            });
        }
    };
    /* 模态框对象 */
    $containerObj.modalObj = {
        main: $('#detail-modal'), // 模态框主对象
        assetsMain: $('#assets-modal'), // 设备、新增、报废设备详情， 覆盖 header
        yearMain: $('#year-modal'), // 历年数据模态框
        data: {}, // 模态框数据
        /* 初始化模态框对象 */
        init: function () {
            this.initModal(); // 初始化模态框
            this.bindEvent(); // 绑定事件
        },
        /* 初始化模态框 */
        initModal: function () {
            var $this = this;
            /* 历年数据模态框 */
            this.yearMain.iziModal({
                title: 'title',
                headerColor: '#222431',
                width: '100%',
                radius: 3,
                zindex: 70,
                history: false,
                bodyOverflow: true,
                fullscreen: true,
                overlayColor: 'rgba(0, 0, 0, 0)',
                onOpening: function () {
                    /* 添加导出按钮 */
                    if (!$this.yearMain.find('.iziModal-header').find('.export_excel').length) {
                        $this.yearMain.find('.iziModal-header').append('<a class="iziModal-button export_excel"' +
                            ' href="javascript:void(0);" onclick="exportExcel(\'#year-modal\')" title="'+$.i18n.prop('share.sift.dc')+'"><i class="fa' +
                            ' fa-upload"></i></a>');
                    }
                },
                onOpened: function () {
                    /* 设置模态框高度 */
                    var height = $this.yearMain.height() - $this.yearMain.find('.iziModal-header').outerHeight();
                    $this.yearMain.find('.iziModal-content').height(height);
                }
            });
            /* 主模态框 */
            this.main.iziModal({
                title: 'title',
                headerColor: '#222431',
                width: '100%',
                radius: 3,
                zindex: 80,
                history: false,
                bodyOverflow: true,
                fullscreen: true,
                overlayColor: 'rgba(0, 0, 0, 0)',
                onOpening: function () {
                    /* 添加导出按钮 */
                    if (!$this.main.find('.iziModal-header').find('.export_excel').length) {
                        $this.main.find('.iziModal-header').append('<a class="iziModal-button export_excel" href="javascript:void(0);" onclick="exportExcel(\'#detail-modal\')" title="'+$.i18n.prop('share.sift.dc')+'"><i class="fa fa-upload"></i></a>');
                    }
                },
                onOpened: function () {
                    /* 设置模态框高度 */
                    var height = $this.main.height() - $this.main.find('.iziModal-header').outerHeight();
                    $this.main.find('.iziModal-content').height(height);
                }
            });
            /* 设备、新增、报废模态框 */
            this.assetsMain.iziModal({
                title: $.i18n.prop('share.talbe.sbxq'),
                headerColor: '#222431',
                width: '100%',
                radius: 3,
                zindex: 111,
                history: false,
                bodyOverflow: true,
                fullscreen: true,
                overlayColor: 'rgba(0, 0, 0, 0)',
                onOpening: function () {
                    /* 添加导出按钮 */
                    if (!$this.assetsMain.find('.iziModal-header').find('.export_excel').length) {
                        $this.assetsMain.find('.iziModal-header').append('<a class="iziModal-button export_excel" href="javascript:void(0);" onclick="exportExcel(\'#assets-modal\')" title="'+$.i18n.prop('share.sift.dc')+'"><i class="fa fa-upload"></i></a>');
                    }
                },
                onOpened: function () {
                    /* 设置模态框高度 */
                    var height = $this.assetsMain.height() - $this.assetsMain.find('.iziModal-header').outerHeight();
                    $this.assetsMain.find('.iziModal-content').height(height);
                }
            });
            // 历年数据表格对象
            this.yearTable = this.yearMain.find('#year-table');
            this.yearThead = this.yearTable.find('thead');
            this.yearTbody = this.yearTable.find('tbody');
            this.yearTfoot = this.yearTable.find('tfoot');
            // 主表格对象
            this.table = this.main.find('#detail-table');
            this.thead = this.table.find('thead');
            this.tbody = this.table.find('tbody');
            this.tfoot = this.table.find('tfoot');
            // 设备表格对象
            this.assetsTable = this.assetsMain.find('#assets-table');
            this.assetsThead = this.assetsTable.find('thead');
            this.assetsTbody = this.assetsTable.find('tbody');
            this.assetsTfoot = this.assetsTable.find('tfoot');
        },
        /* 设置模态框数据 */
        setModal: function (tag, key, sorting, param) {
            var $this = this;
            loading(function () {
                var theadStr = '',
                    tbodyStr = '',
                    tfootStr = '',
                    list = $.extend([], $this.data[tag].list).calTotal().sortByKey(sorting, key);  // 数据列表根据key排序，sorting郑旭或倒序
                // 清空表格内容
                $this.thead.html('');
                $this.tbody.html('');
                $this.tfoot.html('');
                $this.main.data().tag = tag; // 设置tag，用于模态框显示时，筛选刷新模态框数据
                if (tag === 'hospital') {
                    $this.main.iziModal('setTitle', $.i18n.prop('share.table.title.yljgfbxq'));
                    theadStr = (
                        '<tr><th class="tc">#</th>' +
                        '<th class="sort tl" data-key="name">' + $.i18n.prop('index.table.yymc') + '</th>' +
                        '<th class="sort tr" data-key="curPrice">'+$.i18n.prop('index.table.sbje(wy)')+'</th>' +
                        '<th class="sort tr" data-key="curBeginPrice">'+$.i18n.prop('index.table.ncsbje(wy)')+'</th>' +
                        '<th class="sort tr" data-key="curCounts">'+$.i18n.prop('index.table.sbsl(t)')+'</th>' +
                        '<th class="sort tr" data-key="curNewlyCounts">'+$.i18n.prop('index.table.xzsbsl(t)')+'</th>' +
                        '<th class="sort tr" data-key="curScrapCounts">'+$.i18n.prop('index.table.bfsl(t)')+'</th>' +
                        '<th class="sort tr" data-key="devicePriceYoy">'+$.i18n.prop('index.table.sbjetb(%)')+'</th>' +
                        '<th class="sort tr" data-key="deviceCountsYoy">'+$.i18n.prop('index.table.sbsltb(%)')+'</th>' +
                        '<th class="sort tr" data-key="curDepreciationPrice">'+$.i18n.prop('index.table.zjje(wy)')+'</th>' +
                        '<th class="sort tr" data-key="curAgeLimitMeasure">'+$.i18n.prop('index.table.nxzs')+'</th>' +
                        '</tr>'
                    );
                    tfootStr = (
                        '<tr>' +
                        '<td class="tc">'+$.i18n.prop('share.table.tail.zj')+'</td>' +
                        '<td class="tl">' + list.length + '</td>' +
                        '<td class="tr">' + fix2(list[-1].curPrice / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].curBeginPrice / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix0(list[-1].curCounts) + '</td>' +
                        '<td class="tr">' + fix0(list[-1].curNewlyCounts) + '</td>' +
                        '<td class="tr">' + fix0(list[-1].curScrapCounts) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].devicePriceYoy / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].deviceCountsYoy / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].curDepreciationPrice / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].curAgeLimitMeasure / list.length) + '</td>' +
                        '</tr>'
                    );
                    for (var i = 0; i < list.length; i++) {
                        tbodyStr += (
                            '<tr>' +
                            '<td class="tc">' + (i + 1) + '</td>' +
                            '<td class="spanTitle" onclick="$containerObj.query(\'' + tag + '\',\'' + list[i].id + '\')">' + fixStr(list[i].name) + '</td>' +
                            '<td class="tr">' + fix2(list[i].curPrice / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].curBeginPrice / PRICE_CONVERT) + '</td>' +
                            '<td class="tr' + (list[i].curCounts ? ' spanTitle' : '') +
                            '" onclick="$containerObj.modalObj.query(\'count\',\'{hospitalId:[' + list[i].id + ']}\',\'' + list[i].curCounts + '\')">' +
                            fix0(list[i].curCounts) + '</td>' +
                            '<td class="tr' + (list[i].curNewlyCounts ? ' spanTitle' : '') +
                            '" onclick="$containerObj.modalObj.query(\'newly\',\'{hospitalId:[' + list[i].id + ']}\',\'' + list[i].curNewlyCounts + '\')">' +
                            fix0(list[i].curNewlyCounts) + '</td>' +
                            '<td class="tr' + (list[i].curScrapCounts ? ' spanTitle' : '') +
                            '" onclick="$containerObj.modalObj.query(\'scrap\',\'{hospitalId:[' + list[i].id + ']}\',\'' + list[i].curScrapCounts + '\')">' +
                            fix0(list[i].curScrapCounts) + '</td>' +
                            '<td class="tr">' + fix2(list[i].devicePriceYoy) + '</td>' +
                            '<td class="tr">' + fix2(list[i].deviceCountsYoy) + '</td>' +
                            '<td class="tr">' + fix2(list[i].curDepreciationPrice / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].curAgeLimitMeasure) + '</td>' +
                            '</tr>'
                        );
                    }
                } else if (tag === 'type') {
                    list[-1].list = list[-1].list || [];
                    $this.main.iziModal('setTitle', $.i18n.prop('share.table.title.sblxfbxq'));
                    theadStr = (
                        '<tr><th class="tl">'+$.i18n.prop('index.table.yjsb')+'</th>' +
                        '<th class="sort tl" data-key="name">'+$.i18n.prop('share.table.head.sblx')+'</th>' +
                        '<th class="sort tr" data-key="curPrice">'+$.i18n.prop('index.table.sbje(wy)')+'</th>' +
                        '<th class="sort tr" data-key="curBeginPrice">'+$.i18n.prop('index.table.ncsbje(wy)')+'</th>' +
                        '<th class="sort tr" data-key="curCounts">'+$.i18n.prop('index.table.sbsl(t)')+'</th>' +
                        '<th class="sort tr" data-key="curNewlyCounts">'+$.i18n.prop('index.table.xzsbsl(t)')+'</th>' +
                        '<th class="sort tr" data-key="curScrapCounts">'+$.i18n.prop('index.table.bfsl(t)')+'</th>' +
                        '<th class="sort tr" data-key="devicePriceYoy">'+$.i18n.prop('index.table.sbjetb(%)')+'</th>' +
                        '<th class="sort tr" data-key="deviceCountsYoy">'+$.i18n.prop('index.table.sbsltb(%)')+'</th>' +
                        '<th class="sort tr" data-key="curDepreciationPrice">'+$.i18n.prop('index.table.zjje(wy)')+'</th>' +
                        '<th class="sort tr" data-key="curAgeLimitMeasure">'+$.i18n.prop('index.table.nxzs')+'</th>' +
                        '</tr>'
                    );
                    tfootStr = (
                        '<tr>' +
                        '<td class="tl">'+$.i18n.prop('share.table.tail.zj')+' ' + list.length + '</td>' +
                        '<td class="tl">' + list[-1].list.length + '</td>' +
                        '<td class="tr">' + fix2(list[-1].curPrice / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].curBeginPrice / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix0(list[-1].curCounts) + '</td>' +
                        '<td class="tr">' + fix0(list[-1].curNewlyCounts) + '</td>' +
                        '<td class="tr">' + fix0(list[-1].curScrapCounts) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].devicePriceYoy / list[-1].list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].deviceCountsYoy / list[-1].list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].curDepreciationPrice / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].curAgeLimitMeasure / list[-1].list.length) + '</td>' +
                        '</tr>'
                    );
                    for (var i = 0; i < list.length; i++) {
                        tbodyStr += (
                            '<tr>' +
                            '<td class="tl border-bottom" rowspan="' + (list[i].list.length + 1) + '">' + fixStr(list[i].name) + '</td>' +
                            '<td class="tl">'+$.i18n.prop('share.table.tail.xj')+'</td>' +
                            '<td class="tr">' + fix2(list[i].curPrice / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].curBeginPrice / PRICE_CONVERT) + '</td>' +
                            '<td class="tr' + (list[i].curCounts ? ' spanTitle' : '') +
                            '" onclick="$containerObj.modalObj.query(\'count\',\'{typeId:[' + list[i].id + ']'+(param||'')+'}\',\'' + list[i].curCounts + '\')">' +
                            fix0(list[i].curCounts) + '</td>' +
                            '<td class="tr' + (list[i].curNewlyCounts ? ' spanTitle' : '') +
                            '" onclick="$containerObj.modalObj.query(\'newly\',\'{typeId:[' + list[i].id + ']'+(param||'')+'}\',\'' + list[i].curNewlyCounts + '\')">' +
                            fix0(list[i].curNewlyCounts) + '</td>' +
                            '<td class="tr' + (list[i].curScrapCounts ? ' spanTitle' : '') +
                            '" onclick="$containerObj.modalObj.query(\'scrap\',\'{typeId:[' + list[i].id + ']'+(param||'')+'}\',\'' + list[i].curScrapCounts + '\')">' +
                            fix0(list[i].curScrapCounts) + '</td>' +
                            '<td class="tr">' + fix2(list[i].devicePriceYoy) + '</td>' +
                            '<td class="tr">' + fix2(list[i].deviceCountsYoy) + '</td>' +
                            '<td class="tr">' + fix2(list[i].curDepreciationPrice / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].curAgeLimitMeasure) + '</td>' +
                            '</tr>'
                        );
                        var selist = list[i].list;
                        for (var k = 0; k < selist.length; k++) {
                            tbodyStr += (
                                '<tr' + (k === selist.length - 1 ? ' class="border-bottom"' : '') + '>' +
                                '<td class="spanTitle" onclick="$containerObj.query(\'' + tag + '\',\'' + selist[k].id + '\')">' + fixStr(selist[k].name) + '</td>' +
                                '<td class="tr">' + fix2(selist[k].curPrice / PRICE_CONVERT) + '</td>' +
                                '<td class="tr">' + fix2(selist[k].curBeginPrice / PRICE_CONVERT) + '</td>' +
                                '<td class="tr' + (selist[k].curCounts ? ' spanTitle' : '') +
                                '" onclick="$containerObj.modalObj.query(\'count\',\'{typeId:[' + selist[k].id + ']'+(param||'')+'}\',\'' + selist[k].curCounts + '\')">' +
                                fix0(selist[k].curCounts) + '</td>' +
                                '<td class="tr' + (selist[k].curNewlyCounts ? ' spanTitle' : '') +
                                '" onclick="$containerObj.modalObj.query(\'newly\',\'{typeId:[' + selist[k].id + ']'+(param||'')+'}\',\'' + selist[k].curNewlyCounts + '\')">' +
                                fix0(selist[k].curNewlyCounts) + '</td>' +
                                '<td class="tr' + (selist[k].curScrapCounts ? ' spanTitle' : '') +
                                '" onclick="$containerObj.modalObj.query(\'scrap\',\'{typeId:[' + selist[k].id + ']'+(param||'')+'}\',\'' + selist[k].curScrapCounts + '\')">' +
                                fix0(selist[k].curScrapCounts) + '</td>' +
                                '<td class="tr">' + fix2(selist[k].devicePriceYoy) + '</td>' +
                                '<td class="tr">' + fix2(selist[k].deviceCountsYoy) + '</td>' +
                                '<td class="tr">' + fix2(selist[k].curDepreciationPrice / PRICE_CONVERT) + '</td>' +
                                '<td class="tr">' + fix2(selist[k].curAgeLimitMeasure) + '</td>' +
                                '</tr>'
                            );
                        }
                    }
                } else if (tag === 'assets') {
                    $this.main.iziModal('setTitle', $.i18n.prop('share.table.title.sbfbxq'));
                    theadStr = (
                        '<tr><th class="tc">#</th>' +
                        '<th class="sort tl" data-key="name">'+$.i18n.prop('share.assets.sbmc')+'</th>' +
                        '<th class="sort tl" data-key="modalName">'+$.i18n.prop('share.assets.sbxh')+'</th>' +
                        '<th class="sort tl" data-key="firstTypeName">'+$.i18n.prop('share.table.head.sblx')+'</th>' +
                        '<th class="sort tl" data-key="hospital">'+$.i18n.prop('share.assets.ssyy')+'</th>' +
                        '<th class="sort tl" data-key="department">'+$.i18n.prop('share.assets.ssks')+'</th>' +
                        '<th class="sort tl" data-key="manufacturer">'+$.i18n.prop('share.table.head.sbcj')+'</th>' +
                        '<th class="sort tl" data-key="sn">'+$.i18n.prop('share.assets.snbh')+'</th>' +
                        '<th class="sort tl" data-key="assetsNo">'+$.i18n.prop('share.assets.zcbh')+'</th>' +
                        '<th class="sort tl" data-key="enableDate">'+$.i18n.prop('share.assets.sbqyrq')+'</th>' +
                        '<th class="sort tr" data-key="price">'+$.i18n.prop('share.assets.sbje(wy)')+'</th>' +
                        '<th class="sort tr" data-key="depreciationPrice">'+$.i18n.prop('share.assets.zjje(wy)')+'</th>' +
                        '<th class="sort tr" data-key="usedTime">'+$.i18n.prop('share.assets.ysysj(n)')+'</th>' +
                        '<th class="sort tr" data-key="ageLimitMeasure">'+$.i18n.prop('share.assets.nxzs')+'</th>' +
                        '</tr>'
                    );
                    tfootStr = (
                        '<tr>' +
                        '<td class="tc">'+$.i18n.prop('share.table.tail.zj')+'</td>' +
                        '<td class="tl">' + list.length + '</td>' +
                        '<td class="tl"></td>' +
                        '<td class="tl"></td>' +
                        '<td class="tl"></td>' +
                        '<td class="tl"></td>' +
                        '<td class="tl"></td>' +
                        '<td class="tl"></td>' +
                        '<td class="tl"></td>' +
                        '<td class="tl"></td>' +
                        '<td class="tr">' + fix2(list[-1].price / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].depreciationPrice / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].usedTime / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].ageLimitMeasure / list.length) + '</td>' +
                        '</tr>'
                    );
                    for (var i = 0; i < list.length; i++) {
                        tbodyStr += (
                            '<tr>' +
                            '<td class="tc">' + (i + 1) + '</td>' +
                            '<td class="spanTitle" onclick="$containerObj.query(\'' + tag + '\',\'' + list[i].id + '\')">' + fixStr(list[i].name) + '</td>' +
                            '<td class="tl">' + fixStr(list[i].modalName) + '</td>' +
                            '<td class="tl">' + fixStr(list[i].firstTypeName) + '</td>' +
                            '<td class="tl">' + fixStr(list[i].hospital) + '</td>' +
                            '<td class="tl">' + fixStr(list[i].department) + '</td>' +
                            '<td class="tl">' + fixStr(list[i].manufacturer) + '</td>' +
                            '<td class="tl">' + fixStr(list[i].sn) + '</td>' +
                            '<td class="tl">' + fixStr(list[i].assetsNo) + '</td>' +
                            '<td class="tl">' + fixStr(list[i].enableDate) + '</td>' +
                            '<td class="tr">' + fix2(list[i].price / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].depreciationPrice / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].usedTime) + '</td>' +
                            '<td class="tr">' + fix2(list[i].ageLimitMeasure) + '</td>' +
                            '</tr>'
                        );
                    }
                } else if (tag === 'year') {
                    $this.yearMain.iziModal('setTitle', $.i18n.prop('charts.button.lnsj'));
                    theadStr = (
                        '<tr><th class="tc">#</th>' +
                        '<th class="sort tl" data-key="name">'+$.i18n.prop('share.table.head.nf')+'</th>' +
                        '<th class="sort tr" data-key="curPrice">'+$.i18n.prop('index.table.sbje(wy)')+'</th>' +
                        '<th class="sort tr" data-key="curBeginPrice">'+$.i18n.prop('index.table.ncsbje(wy)')+'</th>' +
                        '<th class="sort tr" data-key="curCounts">'+$.i18n.prop('index.table.sbsl(t)')+'</th>' +
                        '<th class="sort tr" data-key="curNewlyCounts">'+$.i18n.prop('index.table.xzsbsl(t)')+'</th>' +
                        '<th class="sort tr" data-key="curScrapCounts">'+$.i18n.prop('index.table.bfsl(t)')+'</th>' +
                        '<th class="sort tr" data-key="curDepreciationPrice">'+$.i18n.prop('index.table.zjje(wy)')+'</th>' +
                        '<th class="sort tr" data-key="depreciationRatio">'+$.i18n.prop('index.overview.yyks.zjl')+'</th>' +
                        '<th class="sort tr" data-key="curAgeLimitMeasure">'+$.i18n.prop('index.table.nxzs')+'</th>' +
                        '</tr>'
                    );
                    tfootStr = (
                        '<tr>' +
                        '<td class="tc">'+$.i18n.prop('share.table.tail.zj')+'</td>' +
                        '<td class="tl">' + list.length + '</td>' +
                        '<td class="tr">' + fix2(list[-1].curPrice / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].curBeginPrice / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix0(list[-1].curCounts) + '</td>' +
                        '<td class="tr">' + fix0(list[-1].curNewlyCounts) + '</td>' +
                        '<td class="tr">' + fix0(list[-1].curScrapCounts) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].curDepreciationPrice / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].depreciationRatio / list.length) + '</td>' +
                        '<td class="tr">' + fix2(list[-1].curAgeLimitMeasure / list.length) + '</td>' +
                        '</tr>'
                    );
                    for (var i = 0; i < list.length; i++) {
                        tbodyStr += (
                            '<tr>' +
                            '<td class="tc">' + (i + 1) + '</td>' +
                            '<td class="spanTitle" onclick="$containerObj.query(\'' + tag + '\',\'' + list[i].id + '\')">' + fixStr(list[i].name) + '</td>' +
                            '<td class="tr">' + fix2(list[i].curPrice / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].curBeginPrice / PRICE_CONVERT) + '</td>' +
                            '<td class="tr' + (list[i].curCounts ? ' spanTitle' : '') +
                            '" onclick="$containerObj.modalObj.query(\'count\',\'{year:' + list[i].id + '}\',\'' + list[i].curCounts + '\')">' +
                            fix0(list[i].curCounts) + '</td>' +
                            '<td class="tr' + (list[i].curNewlyCounts ? ' spanTitle' : '') +
                            '" onclick="$containerObj.modalObj.query(\'newly\',\'{year:' + list[i].id + '}\',\'' + list[i].curNewlyCounts + '\')">' +
                            fix0(list[i].curNewlyCounts) + '</td>' +
                            '<td class="tr' + (list[i].curScrapCounts ? ' spanTitle' : '') +
                            '" onclick="$containerObj.modalObj.query(\'scrap\',\'{year:' + list[i].id + '}\',\'' + list[i].curScrapCounts + '\')">' +
                            fix0(list[i].curScrapCounts) + '</td>' +
                            '<td class="tr">' + fix2(list[i].curDepreciationPrice / PRICE_CONVERT) + '</td>' +
                            '<td class="tr">' + fix2(list[i].depreciationRatio) + '</td>' +
                            '<td class="tr">' + fix2(list[i].curAgeLimitMeasure) + '</td>' +
                            '</tr>'
                        );
                    }
                }
                var table, thead, tbody, tfoot, main;
                if (tag === 'year') {
                    table = $this.yearTable;
                    thead = $this.yearThead;
                    tbody = $this.yearTbody;
                    tfoot = $this.yearTfoot;
                    main = $this.yearMain;
                } else {
                    table = $this.table;
                    thead = $this.thead;
                    tbody = $this.tbody;
                    tfoot = $this.tfoot;
                    main = $this.main;
                }
                thead.html(theadStr);
                tbody.html(tbodyStr);
                tfoot.html(tfootStr);
                /* 排序 */
                // 添加排序图片
                var sort = thead.find('.sort').append('<img src="' + basePath + 'plugins/charts/images/sort.png">').each(function () {
                    if (key === $(this).data().key) { // 根据sorting和key设置排序字段图片
                        $(this).find('img').attr('src', basePath + 'plugins/charts/images/sort_' + (sorting === 'desc' ? 'up' : 'down') + '.png');
                    }
                });
                /* 点击表头重新排序 */
                sort.on('click', function () {
                    var src = $(this).find('img').attr('src');
                    if (src.indexOf('sort_up.png') !== -1) {
                        $containerObj.modalObj.setModal(tag, $(this).data().key, 'asc');
                    } else if ((src.indexOf('sort_down.png') !== -1) || (src.indexOf('sort.png') !== -1)) {
                        $containerObj.modalObj.setModal(tag, $(this).data().key, 'desc');
                    }
                });
                main.iziModal('open');
                // 延时设置表格首尾固定，防止页面卡死
                setTimeout(function () {
                    // 如果列表长度大于200，则值固定表头表尾，不固定前两列，防止页面卡死
                    if (list.length > 200) {
                        table.tableHeadFixer({'head': true, 'foot': true});
                    } else {
                        table.tableHeadFixer({'left': 2, 'head': true, 'foot': true});
                    }
                    loading(true);
                }, 20);
            }, 20);
        },
        /* 绑定事件 */
        bindEvent: function () {
            var $this = this;
            // 点击详情按钮，设置对应数据，弹出模态框
            $containerObj.main.find('.detail-btn').on('click', function () {
                var tag = $(this).data().tag;
                if (tag === 'year') {
                    $this.setModal(tag, 'id', 'asc');
                } else {
                    $this.setModal(tag, 'curPrice', 'desc');
                }
            })
        },
        /* 处理新增、报废、设备的点击 */
        query: function (tag, params, count) {
            if (count > 0) {
                var $this = this;
                loading(function () {
                    params = string2json(params);
                    if (tag === 'count') {
                        $this.queryAssetsTable('assets', params);
                        $this.assetsMain.iziModal('setTitle', $.i18n.prop('share.table.title.sbfbxq'));
                    } else if (tag === 'newly') {
                        params.assetsTag = 1;
                        $this.queryAssetsTable('new-or-scrap', params);
                        $this.assetsMain.iziModal('setTitle', $.i18n.prop('share.table.title.xzsbfbxq'));
                    } else if (tag === 'scrap') {
                        params.assetsTag = 2;
                        $this.queryAssetsTable('new-or-scrap', params, tag);
                        $this.assetsMain.iziModal('setTitle', $.i18n.prop('share.table.title.bfsbfbxq'));
                    }
                });
            }
        },
        /* 查询设备、新增、报废数据 */
        queryAssetsTable: function (url, params, tag) {
            var $this = this;
            publicAjax(basePath + 'charts/area/allocation/' + url, 'post', $.extend({}, $headerObj.searchObj.params, params), function (data) {
                $this.data.count = data.data;
                $this.setAssetsTable(url, 'price', 'desc', tag);
            }, true);
        },
        /* 设置设备、新增、报废表格数据 */
        setAssetsTable: function (tag, key, sorting, tag1) {
            var $this = this,
                theadStr = '',
                tbodyStr = '',
                tfootStr = '',
                list = (this.data.count.list || []).calTotal().sortByKey(sorting, key);
            loading();
            if (tag === 'assets') {
                theadStr = (
                    '<tr><th class="tc">#</th>' +
                    '<th class="sort tl" data-key="name">'+$.i18n.prop('share.table.head.sbmc')+'</th>' +
                    '<th class="sort tl" data-key="modalName">'+$.i18n.prop('share.table.head.sbxh')+'</th>' +
                    '<th class="sort tl" data-key="firstTypeName">'+$.i18n.prop('share.table.head.sblx')+'</th>' +
                    '<th class="sort tl" data-key="hospital">'+$.i18n.prop('share.assets.ssyy')+'</th>' +
                    '<th class="sort tl" data-key="department">'+$.i18n.prop('share.assets.ssks')+'</th>' +
                    '<th class="sort tl" data-key="manufacturer">'+$.i18n.prop('share.table.head.sbcj')+'</th>' +
                    '<th class="sort tl" data-key="sn">'+$.i18n.prop('share.assets.snbh')+'</th>' +
                    '<th class="sort tl" data-key="assetsNo">'+$.i18n.prop('share.assets.zcbh')+'</th>' +
                    '<th class="sort tl" data-key="enableDate">'+$.i18n.prop('share.assets.sbqyrq')+'</th>' +
                    '<th class="sort tr" data-key="price">'+$.i18n.prop('share.assets.sbje(wy)')+'</th>' +
                    '<th class="sort tr" data-key="depreciationPrice">'+$.i18n.prop('share.assets.zjje(wy)')+'</th>' +
                    '<th class="sort tr" data-key="usedTime">'+$.i18n.prop('share.assets.ysysj(n)')+'</th>' +
                    '<th class="sort tr" data-key="ageLimitMeasure">'+$.i18n.prop('share.assets.nxzs')+'</th>' +
                    '</tr>'
                );
                tfootStr = (
                    '<tr>' +
                    '<td class="tc">'+$.i18n.prop('share.table.tail.zj')+'</td>' +
                    '<td class="tl">' + list.length + '</td>' +
                    '<td class="tl"></td>' +
                    '<td class="tl"></td>' +
                    '<td class="tl"></td>' +
                    '<td class="tl"></td>' +
                    '<td class="tl"></td>' +
                    '<td class="tl"></td>' +
                    '<td class="tl"></td>' +
                    '<td class="tl"></td>' +
                    '<td class="tr">' + fix2(list[-1].price / PRICE_CONVERT) + '</td>' +
                    '<td class="tr">' + fix2(list[-1].depreciationPrice / PRICE_CONVERT) + '</td>' +
                    '<td class="tr">' + fix2(list[-1].usedTime / list.length) + '</td>' +
                    '<td class="tr">' + fix2(list[-1].ageLimitMeasure / list.length) + '</td>' +
                    '</tr>'
                );
                for (var i = 0; i < list.length; i++) {
                    tbodyStr += (
                        '<tr>' +
                        '<td class="tc">' + (i + 1) + '</td>' +
                        '<td class="spanTitle" onclick="$containerObj.query(\'assets\',\'' + list[i].id + '\')">' + fixStr(list[i].name) + '</td>' +
                        '<td class="tl">' + fixStr(list[i].modalName) + '</td>' +
                        '<td class="tl">' + fixStr(list[i].firstTypeName) + '</td>' +
                        '<td class="tl">' + fixStr(list[i].hospital) + '</td>' +
                        '<td class="tl">' + fixStr(list[i].department) + '</td>' +
                        '<td class="tl">' + fixStr(list[i].manufacturer) + '</td>' +
                        '<td class="tl">' + fixStr(list[i].sn) + '</td>' +
                        '<td class="tl">' + fixStr(list[i].assetsNo) + '</td>' +
                        '<td class="tl">' + fixStr(list[i].enableDate) + '</td>' +
                        '<td class="tr">' + fix2(list[i].price / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[i].depreciationPrice / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[i].usedTime) + '</td>' +
                        '<td class="tr">' + fix2(list[i].ageLimitMeasure) + '</td>' +
                        '</tr>'
                    );
                }
            } else {
                theadStr = (
                    '<tr><th class="tc">#</th>' +
                    '<th class="sort tl" data-key="name">'+$.i18n.prop('share.table.head.sbmc')+'</th>' +
                    '<th class="sort tl" data-key="modalName">'+$.i18n.prop('share.table.head.sbxh')+'</th>' +
                    '<th class="sort tl" data-key="firstTypeName">'+$.i18n.prop('share.table.head.sblx')+'</th>' +
                    '<th class="sort tl" data-key="hospital">'+$.i18n.prop('share.assets.ssyy')+'</th>' +
                    '<th class="sort tl" data-key="department">'+$.i18n.prop('share.assets.ssks')+'</th>' +
                    '<th class="sort tl" data-key="manufacturer">'+$.i18n.prop('share.table.head.sbcj')+'</th>' +
                    '<th class="sort tl" data-key="sn">'+$.i18n.prop('share.assets.snbh')+'</th>' +
                    '<th class="sort tl" data-key="assetsNo">'+$.i18n.prop('share.assets.zcbh')+'</th>' +
                    '<th class="sort tr" data-key="price">'+$.i18n.prop('share.assets.sbje(wy)')+'</th>' +
                    '<th class="sort tr" data-key="depreciationPrice">'+$.i18n.prop('share.assets.zjje(wy)')+'</th>' +
                    '<th class="sort tl" data-key="enableDate">'+$.i18n.prop('share.assets.sbqyrq')+'</th>' +
                    (tag1 === 'scrap' ? '<th class="sort tl" data-key="scrapTime">'+$.i18n.prop('share.assets.sbbfrq')+'</th>' : '') +
                    '<th class="sort tr" data-key="usedTime">'+$.i18n.prop('share.assets.ysysj(n)')+'</th>' +
                    '<th class="sort tr" data-key="ageLimitMeasure">'+$.i18n.prop('share.assets.nxzs')+'</th>' +
                    '</tr>'
                );
                tfootStr = (
                    '<tr>' +
                    '<td class="tc">'+$.i18n.prop('share.table.tail.zj')+'</td>' +
                    '<td class="tl">' + list.length + '</td>' +
                    '<td class="tl"></td>' +
                    '<td class="tl"></td>' +
                    '<td class="tl"></td>' +
                    '<td class="tl"></td>' +
                    '<td class="tl"></td>' +
                    '<td class="tl"></td>' +
                    '<td class="tl"></td>' +
                    '<td class="tr">' + fix2(list[-1].price / PRICE_CONVERT) + '</td>' +
                    '<td class="tr">' + fix2(list[-1].depreciationPrice / PRICE_CONVERT) + '</td>' +
                    '<td class="tl"></td>' +
                    (tag1 === 'scrap' ? '<td class="tl"></td>' : '') +
                    '<td class="tr">' + fix2(list[-1].usedTime / list.length) + '</td>' +
                    '<td class="tr">' + fix2(list[-1].ageLimitMeasure / list.length) + '</td>' +
                    '</tr>'
                );
                for (var i = 0; i < list.length; i++) {
                    tbodyStr += (
                        '<tr>' +
                        '<td class="tc">' + (i + 1) + '</td>' +
                        '<td class="spanTitle" onclick="$containerObj.query(\'assets\',\'' + list[i].id + '\')">' + fixStr(list[i].name) + '</td>' +
                        '<td class="tl">' + fixStr(list[i].modalName) + '</td>' +
                        '<td class="tl">' + fixStr(list[i].firstTypeName) + '</td>' +
                        '<td class="tl">' + fixStr(list[i].hospital) + '</td>' +
                        '<td class="tl">' + fixStr(list[i].department) + '</td>' +
                        '<td class="tl">' + fixStr(list[i].manufacturer) + '</td>' +
                        '<td class="tl">' + fixStr(list[i].sn) + '</td>' +
                        '<td class="tl">' + fixStr(list[i].assetsNo) + '</td>' +
                        '<td class="tr">' + fix2(list[i].price / PRICE_CONVERT) + '</td>' +
                        '<td class="tr">' + fix2(list[i].depreciationPrice / PRICE_CONVERT) + '</td>' +
                        '<td class="tl">' + fixStr(list[i].enableDate) + '</td>' +
                        (tag1 === 'scrap' ? '<td class="tl">' + fixStr(list[i].scrapTime) + '</td>' : '')  +
                        '<td class="tr">' + fix2(list[i].usedTime) + '</td>' +
                        '<td class="tr">' + fix2(list[i].ageLimitMeasure) + '</td>' +
                        '</tr>'
                    );
                }
            }
            $this.assetsThead.html(theadStr);
            $this.assetsTbody.html(tbodyStr);
            $this.assetsTfoot.html(tfootStr);
            /* 排序 */
            var sort = $this.assetsThead.find('.sort').append('<img src="' + basePath + 'plugins/charts/images/sort.png">').each(function () {
                if (key === $(this).data().key) {
                    $(this).find('img').attr('src', basePath + 'plugins/charts/images/sort_' + (sorting === 'desc' ? 'up' : 'down') + '.png');
                }
            });
            sort.on('click', function () {
                var src = $(this).find('img').attr('src');
                if (src.indexOf('sort_up.png') !== -1) {
                    $containerObj.modalObj.setAssetsTable(tag, $(this).data().key, 'asc', tag1);
                } else if ((src.indexOf('sort_down.png') !== -1) || (src.indexOf('sort.png') !== -1)) {
                    $containerObj.modalObj.setAssetsTable(tag, $(this).data().key, 'desc', tag1);
                }
            });
            $this.assetsMain.iziModal('open');
            setTimeout(function () {
                if (list.length > 200) {
                    $this.assetsTable.tableHeadFixer({'head': true, 'foot': true});
                } else {
                    $this.assetsTable.tableHeadFixer({'left': 2, 'head': true, 'foot': true});
                }
                loading(true);
            }, 20);
        }
    };
});